<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@include file="/white/common/common.jsp"%>
<%@include file="/white/common/taglibs.jsp"%>
<html>
	<head>
		<script type="text/javascript">
        function submitForm(){
            var searchForm=document.getElementById("workflowForm");
            searchForm.submit();
        }

        function notAllowedLockSelf(id){
            var searchForm=document.getElementById("workflowForm");
            searchForm.action="userAction-"+id+"!lock.action";
            searchForm.submit();
        }


        function validateDelete(){
            var check=document.getElementsByName("selectedIds");
            var a=false;
            for(var i=0;i <check.length;i++){
                if(check[i].checked==true){
                    a=true;
                    break;
                }
            }
            if(a){
                return confirm('你确定要删除?');
            }else{
                alert("请先择你要删除的内容!");
                return false;
            }
        }

        function doNodeDelete(){
            var searchForm=document.getElementById("workflowForm");
            searchForm.action='workflowAction!delete.action';
            searchForm.submit();
            return true;
        }
        
        function doContextDelete(){
            var searchForm=document.getElementById("workflowForm");
            searchForm.action='workflowAction!deleteContext.action';
            searchForm.submit();
            return true;
        }

        function displayResult(){
            var result = "<s:property value='result'/>";
            if(result != null && result != ""){
                alert(result);
            }
        }
        
        function showNodeDetail(workflowId, workflowNodeId){
            var workflowForm=document.getElementById("workflowForm");            
            workflowForm.action="workflowAction-" + workflowId + "!showNodeDetail.action?workflowNodeId=" + workflowNodeId;
            workflowForm.submit();
            return true;
        }
        function editContext(workflowId,contextId){
        	var contextForm = document.getElementById("workflowForm");
        	contextForm.action = "workflowAction-" +workflowId +"!toContextEdit.action?contextId=" +contextId;
        	contextForm.submit();
        	return true;
        }
		 function doAttachmentDelete(){
            var searchForm=document.getElementById("workflowForm");
            searchForm.action='workflowAction!deleteAttachment.action';
            searchForm.submit();
            return true;
        }
        function validateUpload(){
            var check=document.getElementsByName("selectedIds");
            var count = 0;
            for(var i=0;i <check.length;i++){
                if(check[i].checked==true){
                    count ++;
                }
            }
            if(count == 1){
                return true;
            }else{
                alert("只能选择一项");
                return false;
            }
        }
        function doUpload(){
            var searchForm=document.getElementById("workflowForm");
            searchForm.action='workflowAction!toUpload.action';
            searchForm.submit();
            return true;
        }
    //-->
    </script>
	</head>
	<body onload="displayResult()">
		<s:form method="post" id="workflowForm" action="workflowAction!update" theme="simple">
			<s:hidden name="workId" value="%{workflow.workflowId}"></s:hidden>
			<div id="div_title">
				<h3>
					工作流 : <s:label name="workflow.name"/>
				</h3>
				<div id="div_search">
					<!-- Data Form -->
					<%@include file="/white/common/message.jsp"%>
					
						<s:token />
						<table>
							<tr>
								<td width="80">
									名称:
								</td>
								<td>
									<s:textfield name="workflow.name" maxlength="15" />
									<span class="red_star">*</span>
								</td>
							
								<td width="80">
									类型:
								</td>
								<td>
									<s:textfield name="workflow.type" maxlength="15" />
									<span class="red_star">*</span>
								</td>							
								<td width="80">
									状态:
								</td>
								<td>
									<s:select list="workflowStatusMap" headerKey=""
										name="workflow.status" id="workflow.status">
									</s:select>
									<span class="red_star"></span>
								</td>
							</tr>
						</table>

						<div id="div_button">

							<s:submit key="保存"
								action="workflowAction-%{workflow.workflowId}!update"
								onclick="if(validateForm()){return true;}else{return false;}"
								cssClass="input_button" />

							<s:submit key="返回"
								onclick="form.action='workflowAction!queryByPage.action';return true;"
								cssClass="input_button" />
						</div>
				</div>
			</div>
			
			<h3>
				节点设置
			</h3>
			<div id="div_button">
				<authz:authorize ifAnyGranted="SMOOTH_ALL">
					<s:submit value="新增"
						onclick="form.action='workflowAction!toNodeAdd.action';return true;"
						cssClass="input_button" />
				</authz:authorize>				
				<authz:authorize ifAnyGranted="SMOOTH_ALL">
					<input type="button" value="删除"
						onclick="if(validateDelete()){doNodeDelete()}" class="input_button">
				</authz:authorize>
				<%@include file="/white/common/message.jsp"%>
			</div>
			<!--列表 -->
			<table cellpadding="0" cellspacing="0" class="t_list">
				<tr>
					<th>
						<input type="checkbox" onclick="selectCheckbox();"
							name="checkbox2" value="checkbox" />
					</th>
					<!--列表头部 -->
					<th>
						名称
					</th>
					<th>
						类型
					</th>
					<th>
						显示名称
					</th>
					<th>
						设置
					</th>
					<th>
						创建用户
					</th>
					<th>
						创建时间
					</th>
					<th>
						最后修改用户
					</th>
					<th>
						最后修改时间
					</th>

				</tr>
				<s:iterator value="nodeList" status="sindex">
					<tr>
						<td>
							<input type="checkbox" name="selectedIds"
								value="${WORKFLOW_NODE_ID}" id="selectedIds" />
						</td>
						<td>
							<s:property value="NAME" />
						</td>
						<td>
							<s:property value="workflowNodeWorkTypeMap[TYPE]" />
						</td>
						<td>
							<s:property value="DISPLAY_NAME" />
						</td>
						<td>
							<a  href="javascript:showNodeDetail('${workflow.workflowId}','${WORKFLOW_NODE_ID}')" >
				              <img alt="设置" src="ca/images/users.png" width="15" height="15" />
				            </a>
						</td>
						<td>
							<s:property value="CREATE_USER" />
						</td>
						<td>
							<s:property value="CREATE_TIME" />
						</td>
						<td>
							<s:property value="LAST_UPDATE_USER" />
						</td>
						<td>
							<s:property value="LAST_UPDATE_TIME" />
						</td>

					</tr>
				</s:iterator>
			</table>
			<!--列表结束-->		
			
			
			
			<h3>
				参数设置
			</h3>
			
			<div id="div_button">
				<authz:authorize ifAnyGranted="SMOOTH_ALL">
					<s:submit value="新增"
						onclick="form.action='workflowAction!toContextAdd.action';return true;"
						cssClass="input_button" />
				</authz:authorize>				
				<authz:authorize ifAnyGranted="SMOOTH_ALL">
					<input type="button" value="删除"
						onclick="if(validateDelete()){doContextDelete()}" class="input_button">
				</authz:authorize>
				<%@include file="/white/common/message.jsp"%>
			</div>
			<!--列表 -->
			<table cellpadding="0" cellspacing="0" class="t_list">
				<tr>
					<th>
						<input type="checkbox" onclick="selectCheckbox();"
							name="checkbox2" value="checkbox" />
					</th>
					<!--列表头部 -->
					<th>
						名称
					</th>
					<th>
						类型
					</th>
					<th>
						默认值
					</th>
					<th>
						设置
					</th>				

				</tr>
				<s:iterator value="paramList" status="sindex">
					<tr>
						<td>
							<input type="checkbox" name="selectedIds"
								value="${CONTEXT_ID}" id="selectedIds" />
						</td>
						<td>
							<s:property value="PARAM_NAME" />
						</td>
						<td>
							<s:property value="PARAM_TYPE" />
						</td>
						<td>
							<s:property value="DEFAULT_VALUE" />
						</td>
						<td>
							<a  href="javascript:editContext('${workflow.workflowId}','${CONTEXT_ID}')" >
				              <img alt="设置" src="ca/images/users.png" width="15" height="15" />
				            </a>
						</td>
					</tr>
				</s:iterator>
			</table>
			<!--列表结束-->
			<h3>
				工作流附件设置
			</h3>
			<div id="div_button">
				<authz:authorize ifAnyGranted="SMOOTH_ALL">
					<s:submit value="新增"
						onclick="form.action='workflowAction!toAddAttachment.action';return true;"
						cssClass="input_button" />
				</authz:authorize>				
				<authz:authorize ifAnyGranted="SMOOTH_ALL">
					<input type="button" value="删除"
						onclick="if(validateDelete()){doAttachmentDelete()}" class="input_button">
				</authz:authorize>
				<authz:authorize ifAnyGranted="SMOOTH_ALL">
					<input type="button" value="添加附件"
						onclick="if(validateUpload()){doUpload()}" class="input_button" />
				</authz:authorize>	
				<%@include file="/white/common/message.jsp"%>
			</div>
			<!--列表 -->
			<table cellpadding="0" cellspacing="0" class="t_list">
				<tr>
				<!--列表头部 -->
					<th>
						<input type="checkbox" onclick="selectCheckbox();"
							name="checkbox2" value="checkbox" />
					</th>
					<th>
						名称
					</th>
					<th>
						类型
					</th>
					<th>
						描述
					</th>
					<th>
						附件
					</th>
				</tr>
				<s:iterator value="attachmentList" status="sindex">
					<tr>
						<td>
							<input type="checkbox" name="selectedIds"
								value="${ATTACHMENT_ID}" id="selectedIds" />
						</td>
						<td>
							<s:property value="NAME" />
						</td>
						<td>
							<s:property value="TYPE" />
						</td>
						<td>
							<s:property value="DESCRIPTION" />
						</td>
						<td>
							<a href="<s:url value='download.action'>                  
                    				<s:param name='fileName'  
 									value='RESOURCE_ID'/>     
                 					</s:url>">
                 			<s:property value="FNAME" />
                 			</a>
						</td>
					</tr>
				</s:iterator>
			</table>
			<!--列表结束-->
		</s:form>
	</body>
</html>
